import { useUserStore } from '@/store/modules/user'

/**
 * 检查用户是否拥有指定权限
 * @param permissions 权限数组
 * @returns 是否有权限
 */
export function checkPermission(permissions: string[]): boolean {
  const userStore = useUserStore()
  const userPermissions = userStore.permissions || []
  if (!permissions || permissions.length === 0) {
    return true
  }
  return permissions.some((permission) => userPermissions.includes(permission))
}
/**
 * 检查用户是否拥有指定角色
 * @param roles 角色数组
 * @returns 是否有角色
 */
export function checkRole(roles: string[]): boolean {
  const userStore = useUserStore()
  const userRoles = userStore.userInfo.roles || []

  if (!roles || roles.length === 0) {
    return true
  }
  return roles.some((role) => userRoles.includes(role))
}
